local thbattle__lingmeng_tuizhi = fk.CreateSkill {

  name = "thbattle__lingmeng_tuizhi",

  tags = {},

}



thbattle__lingmeng_tuizhi:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return player.phase == Player.NotActive and target == player and player:hasSkill(thbattle__lingmeng_tuizhi.name) and
        not player:isProhibited(Fk:currentRoom().current, Fk:cloneCard("slash"))
  end,
  on_cost = function(self, event, target, player, data)
    local usecard = player.room:askToUseCard(player, {
      pattern = "slash",
      prompt = "#thbattle__lingmeng_tuizhi:" .. player.room.current.id,
      cancelable = true,
      extra_data = { bypass_times = true, bypass_distances = true, must_targets = { player.room.current.id } },
      skill_name = thbattle__lingmeng_tuizhi.name
    })
    event:setCostData(self, usecard)
    return usecard and usecard.card
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:useCard(event:getCostData(self))
  end
})
thbattle__lingmeng_tuizhi:addEffect(fk.EventPhaseEnd, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return #player.room.logic:getActualDamageEvents(1, function(e)
          return e.data.from == target and e.data.to ~= target
        end, Player.HistoryTurn) > 0 and not player:isProhibited(target, Fk:cloneCard("slash"))
        and player:hasSkill(thbattle__lingmeng_tuizhi.name) and player.phase == Player.NotActive and target ~= player and
        target.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local usecard = player.room:askToUseCard(player, {
      pattern = "slash",
      prompt = "#thbattle__lingmeng_tuizhi:" .. player.room.current.id,
      cancelable = true,
      extra_data = { bypass_times = true, bypass_distances = true, must_targets = { player.room.current.id } },
      skill_name = thbattle__lingmeng_tuizhi.name
    })
    event:setCostData(self, usecard)
    return usecard and usecard.card
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:useCard(event:getCostData(self))
  end
})

return thbattle__lingmeng_tuizhi
